home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
gemfxm15.lzh
/
MINICOLR.LZH
/
MINICOLR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-27
|
35KB
|
824 lines
/**************************************************************************
*
* mini_pallete - A little bitty control-panel-like color pallete acc.
*
* Public Domain example program by Ian Lepore.
*
* This is distributed as an example of how to write an accessory using
* my AESFAST public domain GEM bindings. This example uses a few of
* the nifty utilities from AESFAST, but it's pretty much straightforward
* window-handling code.
*
* I built this beast because I have some graphics programs (Mandelbrot
* fractal generators, a spyrograph program, etc), in which one would
* naturally want to change the screen colors on the fly, but the %^$%#*&
* system control panel covers the whole screen in low rez. This acc
* gives a nice itty-bitty moveable window with all the necessary color
* controls in it.
*
* This acc does not behave like the system control panel, in that it
* will not reset the colors the application has set when you call it up.
* On the other hand, the color changes you do with this accessory will
* not be saved if you use 'Save Desktop'. (Hint: You would need to code
* the shel_read() and shel_write() AES functions to make that work.
* Actually doing it is left as an excerise for the reader <grin>).
*
* Also, the order of the colored boxes on the screen corresponds to the
* TOS order of colors, not the VDI order. (EG: The foreground and
* background colors are the first and last boxes, not the first two).
*
* This code is pretty heavily commented. Please excuse me if some of
* the comments seem obvious, but I figure the audience for this will
* include both beginning C programmers, and old-timers who just need to
* see how my bindings work as opposed to other bindings.
*
*************************************************************************/
#include <gemfast.h>
#include <osbind.h>
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define Getcolor(a) ((int)(Setcolor((a), -1)))
#define graf_mkstate graq_mstate /* use Line-A mouse state call */
/**************************************************************************
*
* global vars (gee, there's not many of these for a change...)
*
*************************************************************************/
struct rgb_settings {
char red, grn, blu, filler;
} cur_setting;
int coloridx = 0; /* default color index is # 0 */
#define WI_KIND (MOVER|CLOSER|NAME)
#define NO_WINDOW -1
extern int gl_apid; /* defined in bindings library */
int menu_id ; /* our menu id */
int wi_handle; /* window handle */
GRECT treerect; /* object tree (in window) rect */
char menu_title[] = " Mini Pallete ";
char wind_title[] = " Mini Pallete ";
/**************************************************************************
*
* palttree - The color pallete dialog tree.
*
* This is NOT the output from a resource editor (it was a long time ago,
* but it's been pretty much re-done by hand).
*
* About extended object types...
*
* The ob_type field is a word, but the AES only uses the lower byte of
* it. It has become a sort of standard technique for programs to use
* the upper byte for their own evil purposes. (Really, the object
* structure should have had an 'ob_apspec' longword in it for the
* application's use). Anyway, there is some discussion under the
* 'find_boxchar' routine below on accessing arrays of objects in a tree
* without being sure where the objects are in the tree array. The
* methods discussed below work fine for boxchar objects; the extended
* object type can be used for other types of objects.
*
* For example, suppose you have 10 strings in a dialog box. You want to
* set the ob_spec pointers at runtime to correspond to the elements in
* an array of strings you've defined in your program. You can code a
* lot of C statements using the hard-coded object names, but what if you
* have 50 strings instead of 10? More to the point, what if some hacker
* edits the .RSC file and changes the order of the objects? Bombs, that's
* what. So, you can (with most resource editors) set the extended
* object type for the strings to the numbers 1-10, then at runtime you
* can scan the tree looking for an object with an extended type of 1,
* then set the first string pointer, then scan for 2, and so on. Now,
* no matter where those strings get moved to in the tree structure, they
* will be found at runtime and pointers will be assigned properly.
*
* Now that I've described this nifty string-thing, I should mention that
* this program doesn't use that techique, as it contains no strings in
* the dialog.
*
* This program uses the extended object type to hold the TOS color index
* value that corresponds to the colored box which is the object. This
* is due to the screwy way the ST maps TOS colors to VDI colors. If you
* compare the VDI/object color number in the ob_spec field to the extended
* object type value, you'll see the translation table that maps TOS colors
* to GEM colors. For the ob_type values below which are not described
* by name, the format is 0xcc14, where 'cc' is the TOS color number, and
* '14' is a box type object.
*
* The ob_spec field for box-like objects maps out as follows:
* 0xaabbcdef
* |||||||+-- inside fill color
* ||||||+--- fill pattern and opaque/transparent flag
* |||||+---- text color
* ||||+----- border color
* ||++------ border thickness (neg = outside width, pos = inside width)
* ++-------- ASCII character for boxchar objects, zero for other types
*
* The two objects flagged as HIDETREE are no longer used, and I don't
* want to rebuild the whole tree to remove them (and I've lost the
* .RSC file that this source comes from).
*************************************************************************/
OBJECT palttree[] = {
/* type flags state ob_spec x y w h */
-1, 1, 35, G_BOX, NONE, 0, 0x00000000L, 0x0000, 0x0000, 0x0212, 0x0506,
2, -1, -1, G_BOXCHAR, HIDETREE, 0, 0x05FF1100L, 0x0000, 0x0000, 0x0000, 0x0000,
3, -1, -1, G_BOX, HIDETREE, 0, 0x00FF1121L, 0x0000, 0x0000, 0x0000, 0x0000,
7, 4, 6, G_IBOX, NONE, 0, 0x00001101L, 0x0100, 0x0100, 0x0401, 0x0703,
5, -1, -1, G_BOXCHAR, NONE, 0, 0x52001100L, 0x0200, 0x0100, 0x0001, 0x0001,
6, -1, -1, G_BOXCHAR, NONE, 0, 0x47001100L, 0x0200, 0x0401, 0x0001, 0x0001,
3, -1, -1, G_BOXCHAR, NONE, 0, 0x42001100L, 0x0200, 0x0702, 0x0001, 0x0001,
35, 8, 26, G_IBOX, NONE, 0, 0x00001100L, 0x0501, 0x0200, 0x0210, 0x0603,
17, 9, 16, G_IBOX, NONE, 0, 0x00001100L, 0x0100, 0x0000, 0x0010, 0x0001,
10, -1, -1, G_BOXCHAR, NONE, 0, 0x30FF1100L, 0, 0, 2, 1,
11, -1, -1, G_BOXCHAR, NONE, 0, 0x31FF1100L, 2, 0, 2, 1,
12, -1, -1, G_BOXCHAR, NONE, 0, 0x32FF1100L, 4, 0, 2, 1,
13, -1, -1, G_BOXCHAR, NONE, 0, 0x33FF1100L, 6, 0, 2, 1,
14, -1, -1, G_BOXCHAR, NONE, 0, 0x34FF1100L, 8, 0, 2, 1,
15, -1, -1, G_BOXCHAR, NONE, 0, 0x35FF1100L, 10, 0, 2, 1,
16, -1, -1, G_BOXCHAR, NONE, 0, 0x36FF1100L, 12, 0, 2, 1,
8, -1, -1, G_BOXCHAR, NONE, 0, 0x37FF1100L, 14, 0, 2, 1,
26, 18, 25, G_IBOX, NONE, 0, 0x00001100L, 0x0100, 0x0301, 0x0010, 0x0001,
19, -1, -1, G_BOXCHAR, NONE, 0, 0x30FF1100L, 0, 0, 2, 1,
20, -1, -1, G_BOXCHAR, NONE, 0, 0x31FF1100L, 2, 0, 2, 1,
21, -1, -1, G_BOXCHAR, NONE, 0, 0x32FF1100L, 4, 0, 2, 1,
22, -1, -1, G_BOXCHAR, NONE, 0, 0x33FF1100L, 6, 0, 2, 1,
23, -1, -1, G_BOXCHAR, NONE, 0, 0x34FF1100L, 8, 0, 2, 1,
24, -1, -1, G_BOXCHAR, NONE, 0, 0x35FF1100L, 10, 0, 2, 1,
25, -1, -1, G_BOXCHAR, NONE, 0, 0x36FF1100L, 12, 0, 2, 1,
17, -1, -1, G_BOXCHAR, NONE, 0, 0x37FF1100L, 14, 0, 2, 1,
7, 27